﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Animation;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace MapLibrary
{
    public class SpriteManager
    {

        private Level toEdit;

        public Sprite CurrentSprite { get; set; }

        public SpriteManager()
        {

        }

        public void EditLevel(Level newLevel)
        {
            toEdit = newLevel;
        }

        public void PlaceSprite(SpriteType type, Vector2 worldPos)
        {
            toEdit.AddSprite(type, worldPos);
        }

        public void Draw(SpriteBatch batch, WorldViewport viewport)
        {
            foreach (Sprite s in toEdit.Sprites)
            {
                if (s == CurrentSprite)
                    s.EditorDraw(batch, viewport, Color.Red);
                else
                    s.EditorDraw(batch, viewport, Color.Blue);
            }
        }

        public bool HasHover(Vector2 MouseWorldCoords)
        {
            //if it is in a sprite, select it
            foreach (Sprite sprite in toEdit.Sprites)
            {
                if (sprite.ContainsPoint(MouseWorldCoords))
                {
                    CurrentSprite = sprite;
                    CurrentSprite.Body.Awake = true;
                    return true;
                }
            }

            return false;
        }

        public ITransformable GetHovered(Vector2 MouseWorldCoords)
        {
            //if it is in a sprite, select it
            foreach (Sprite sprite in toEdit.Sprites)
            {
                if (sprite.ContainsPoint(MouseWorldCoords))
                {
                    return sprite;
                }
            }

            return null;
        }

    }
}
